﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fhe
{
  namespace math
  {
    public class AABB : IShape
    {
      public Vec2 Min { get; set; }

      public Vec2 Max { get; set; }

      public bool Inside(Vec2 v)
      {
        return v.X >= Min.X && v.Y >= Min.Y && v.X <= Max.X && v.Y <= Max.Y;
      }

      public Vec2 SurfaceOffset(Vec2 v)
      {
        return new List<Vec2>()
        {
          new Vec2(v.X,Min.Y),
          new Vec2(Min.X,v.Y),
          new Vec2(v.X,Max.Y),
          new Vec2(Max.X,v.Y),
        }
        .OrderByDescending(o => o.SquaredLength())
        .First();
      }
    }
  }
}
